<?php
define("HOME", "C:/AppServ/www/qin");
$out_width = 100;
$out_height = 100;
define("CONVERT_PROGRAM", '"c:\\Program Files\\ImageMagick-6.7.8-Q16\\convert.exe"');
//print_r($_REQUEST);
if (!isset($_REQUEST["x1"]) || empty($_REQUEST["x1"]) 
    ||!isset($_REQUEST["y1"]) || empty($_REQUEST["y1"]) 
    ||!isset($_REQUEST["x2"]) || empty($_REQUEST["x2"])
    ||!isset($_REQUEST["y2"]) || empty($_REQUEST["y2"]))
  {
    die("选取坐标不完整");
  }

$x1 = $_REQUEST['x1'];
$x2 = $_REQUEST['x2'];
$y1 = $_REQUEST['y1'];
$y2 = $_REQUEST['y2'];
$to_width = $_REQUEST['width'];
$to_height = $_REQUEST['height'];

$crop_width = $x2 - $x1;
$crop_height = $y2 - $y1;
$src = HOME."/".$_REQUEST['src'];
$rely = HOME."/".$_REQUEST['src']."rely";
$dst = HOME."/tmp/".md5($src+rand()).".jpg";
$cmd = CONVERT_PROGRAM." -resize ${to_width}x${to_height} ${src} ${rely}";
$str = exec($cmd, $res, $rc);
$cmd = CONVERT_PROGRAM." -crop ${crop_width}x${crop_height}+${x1}+${y1} -resize ${out_width}x${out_height} ${rely} $dst";
//$cmd = "which convert";
/* print $cmd; */
/* print "<br>"; */
$str = exec($cmd, $res, $rc);
//system($cmd, $rc);
//$str = shell_exec($cmd);
/* var_dump($str); */
/* print_r($res); */
/* print $rc; */

die(json_encode(array("resp_id"=>"0000", "resp_data"=>array("res"=>true, "msg"=>"更新头像成功", "cmd"=>$cmd, "icon"=>$dst))));
